// Device/pages/Info/components/fall-component/index.js
const presenceState = {
    0: '进入',
    1: '跌倒',
    3: '离开',
    5: '滞留',
    null: '--'
}
const deviceStatus = {
    '0': '离线',
    '1': '在线'
}
Component({
    /**
     * 组件的初始数据
     */
    data: {
        deviceData: []
    },
    /**
     * 组件的属性列表
     */
    properties: {
        deviceInfo: {
            type: Object,
            value: {}
        }
    },
    observers: {
        deviceInfo(value) {
            const data = new Map([
                ['presence_state', '监测状态'],
                ['device_status', '联网状态'],
                ['signal_strength', '信号强度']
            ]);
            let obj = {
                presence_state: presenceState[value.radar_device_info?.[0]?.presence_state ?? null],
                device_status: deviceStatus[value['device_status']],
                signal_strength: value['signal_strength'] ? `${value['signal_strength']}dBm` : '--'
            }
            let result = [];
            for (let [key, value] of Object.entries(obj)) {
                result.push({
                    key: data.get(key),
                    value,
                    path: '/Device/pages/Analysis/index?type=' + key
                })
            }
            let radarList = value.radar_device_info?.map((item) => {
                return {
                    time: item.create_time,
                    state: presenceState[item.presence_state]
                }
            })
            this.setData({
                deviceData: result,
                radarList
            })
        }
    },



    /**
     * 组件的方法列表
     */
    methods: {
        onDeviceInfoChange(newVal, oldVal) {
        }
    }
})